home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / include / spline.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  4.1 KB  |  128 lines

  1. /* spline.h: manipulate the spline representation.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef SPLINE_H
  20. #define SPLINE_H
  21.  
  22. #include <stdio.h>
  23. #include "bounding-box.h"
  24. #include "types.h"
  25.  
  26.  
  27. /* Third degree is the highest we deal with.  */
  28. typedef enum
  29. {
  30.   LINEAR = 1, QUADRATIC = 2, CUBIC = 3
  31. } polynomial_degree;
  32.  
  33.  
  34. /* A Bezier spline can be represented as four points in the real plane:
  35.    a starting point, ending point, and two control points.  The
  36.    curve always lies in the convex hull defined by the four points.  It
  37.    is also convenient to save the divergence of the spline from the
  38.    straight line defined by the endpoints.  */
  39. typedef struct
  40. {
  41.   real_coordinate_type v[4];    /* The control points.  */
  42.   polynomial_degree degree;
  43.   real linearity;
  44. } spline_type;
  45.  
  46. #define START_POINT(spl)    ((spl).v[0])
  47. #define CONTROL1(spl)        ((spl).v[1])
  48. #define CONTROL2(spl)        ((spl).v[2])
  49. #define END_POINT(spl)        ((spl).v[3])
  50. #define SPLINE_DEGREE(spl)    ((spl).degree)
  51. #define SPLINE_LINEARITY(spl)    ((spl).linearity)
  52.  
  53.  
  54. /* Return a spline structure.  */
  55. extern spline_type new_spline (void);
  56.  
  57. /* Print a spline on the given file.  */
  58. extern void print_spline (FILE *, spline_type);
  59.  
  60. /* Evaluate SPLINE at the given T value.  */
  61. extern real_coordinate_type evaluate_spline (spline_type spline, real t);
  62.  
  63.  
  64.  
  65. /* Each outline in a character is typically represented by many
  66.    splines.  So, here is a list structure for that:  */
  67. typedef struct
  68. {
  69.   spline_type *data;
  70.   unsigned length;
  71. } spline_list_type;
  72.  
  73. /* An empty list will have length zero (and null data).  */
  74. #define SPLINE_LIST_LENGTH(s_l) ((s_l).length)
  75.  
  76. /* The address of the beginning of the array of data.  */
  77. #define SPLINE_LIST_DATA(s_l) ((s_l).data)
  78.  
  79. /* The element INDEX in S_L.  */
  80. #define SPLINE_LIST_ELT(s_l, index) (SPLINE_LIST_DATA (s_l)[index])
  81.  
  82. /* The last element in S_L.  */
  83. #define LAST_SPLINE_LIST_ELT(s_l) \
  84.   (SPLINE_LIST_DATA (s_l)[SPLINE_LIST_LENGTH (s_l) - 1])
  85.  
  86. /* The previous and next elements to INDEX in S_L.  */
  87. #define NEXT_SPLINE_LIST_ELT(s_l, index)                \
  88.   SPLINE_LIST_ELT (s_l, ((index) + 1) % SPLINE_LIST_LENGTH (s_l))
  89. #define PREV_SPLINE_LIST_ELT(s_l, index)                \
  90.   SPLINE_LIST_ELT (s_l, index == 0                    \
  91.                         ? SPLINE_LIST_LENGTH (s_l) - 1            \
  92.                         : index - 1)
  93.  
  94. /* Construct and destroy new `spline_list_type' objects.  */
  95. extern spline_list_type *new_spline_list (void);
  96. extern spline_list_type *init_spline_list (spline_type);
  97. extern void free_spline_list (spline_list_type *);
  98.  
  99. /* Append the spline S to the list S_LIST.  */
  100. extern void append_spline (spline_list_type *s_list, spline_type s);
  101.  
  102. /* Append the elements in list S2 to S1, changing S1.  */
  103. extern void concat_spline_lists (spline_list_type *s1, spline_list_type s2);
  104.  
  105.  
  106.  
  107. /* Each character is in general made up of many outlines. So here is one
  108.    more list structure.  */
  109. typedef struct
  110. {
  111.   spline_list_type *data;
  112.   unsigned length;
  113. } spline_list_array_type;
  114.  
  115. /* Turns out we can use the same definitions for lists of lists as for
  116.    just lists.  But we define the usual names, just in case.  */
  117. #define SPLINE_LIST_ARRAY_LENGTH SPLINE_LIST_LENGTH
  118. #define SPLINE_LIST_ARRAY_DATA SPLINE_LIST_DATA
  119. #define SPLINE_LIST_ARRAY_ELT SPLINE_LIST_ELT
  120. #define LAST_SPLINE_LIST_ARRAY_ELT LAST_SPLINE_LIST_ELT
  121.  
  122. /* The usual routines.  */
  123. extern spline_list_array_type new_spline_list_array (void);
  124. extern void free_spline_list_array (spline_list_array_type *);
  125. extern void append_spline_list (spline_list_array_type *, spline_list_type);
  126.  
  127. #endif /* not SPLINE_H */
  128.